package com.example.musicserver.mapper;

import com.example.musicserver.model.Music;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface LoveMusicMapper {

    /**
     * 点赞收藏之前，查询是否已经收藏了
     * @param userId
     * @param musicId
     * @return
     */
    @Select("select * from lovemusic where user_id=#{userId} and music_id=#{musicId}")
    Music findLoveMusicByMusicIdAndUserId(Integer userId, Integer musicId);

    /**
     * 收藏音乐
     * @param userId
     * @param musicId
     * @return
     */
    @Insert("insert into lovemusic(user_id,music_id) values(#{userId},#{musicId})")
    boolean insertIntoLoveMusic(Integer userId, Integer musicId);

    /**
     * 查询用户全部收藏音乐
     * @param userId
     * @return
     */
    @Select("select m.* from lovemusic lm,music m where m.id = lm.music_id and lm.user_id=#{userId};")
    List<Music> findLoveMusicByUserId(Integer userId);

    /**
     * 查询用户特定收藏音乐
     * @param userId
     * @param musicName
     * @return
     */
    @Select("select m.* from lovemusic lm,music m where m.id = lm.music_id and lm.user_id=#{userId} and title like concat('%',#{musicName},'%')")
    List<Music> findLoveMusicBykeyAndUID(Integer userId,String musicName);

    /**
     * 取消收藏音乐
     * @param userId
     * @param musicId
     * @return
     */
    @Delete("delete from lovemusic where user_id=#{userId} and music_id=#{musicId}")
    boolean deleteLikeMusic(Integer userId,Integer musicId);

    /**
     * 删除数据库音乐的同时，删去收藏夹中的音乐
     * @param musicId
     * @return
     */
    @Delete("delete from lovemusic where music_id=#{musicId}")
    boolean deleteMusicInLikeByMusicId(Integer musicId);
}
